From 768957a8de1534f0aa91bfc5d7af3c32f222beb8 Mon Sep 17 00:00:00 2001
From: Maarten Baert <maarten-baert@hotmail.com>
Date: Sun, 20 Mar 2022 22:52:43 +0100
Subject: [PATCH] Fix for compatibility with newer FFmpeg versions

---
 src/AV/Output/AudioEncoder.cpp | 3 ++-
 src/AV/Output/Muxer.cpp        | 6 ++++--
 src/AV/Output/VideoEncoder.cpp | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/AV/Output/AudioEncoder.cpp b/src/AV/Output/AudioEncoder.cpp
index 34d015cf..3efde703 100644
--- a/src/AV/Output/AudioEncoder.cpp
+++ b/src/AV/Output/AudioEncoder.cpp
@@ -77,7 +77,8 @@ unsigned int AudioEncoder::GetSampleRate() {
 }
 
 bool AudioEncoder::AVCodecIsSupported(const QString& codec_name) {
-	AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
+	// we have to break const correctness for compatibility with older ffmpeg versions
+	AVCodec *codec = (AVCodec*) avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
 	if(codec == NULL)
 		return false;
 	if(!av_codec_is_encoder(codec))
diff --git a/src/AV/Output/Muxer.cpp b/src/AV/Output/Muxer.cpp
index ad583803..bc6dd71c 100644
--- a/src/AV/Output/Muxer.cpp
+++ b/src/AV/Output/Muxer.cpp
@@ -194,7 +194,8 @@ unsigned int Muxer::GetQueuedPacketCount(unsigned int stream_index) {
 void Muxer::Init() {
 
 	// get the format we want (this is just a pointer, we don't have to free this)
-	AVOutputFormat *format = av_guess_format(m_container_name.toUtf8().constData(), NULL, NULL);
+	// we have to break const correctness for compatibility with older ffmpeg versions
+	AVOutputFormat *format = (AVOutputFormat*) av_guess_format(m_container_name.toUtf8().constData(), NULL, NULL);
 	if(format == NULL) {
 		Logger::LogError("[Muxer::Init] " + Logger::tr("Error: Can't find chosen output format!"));
 		throw LibavException();
@@ -262,7 +263,8 @@ void Muxer::Free() {
 }
 
 AVCodec* Muxer::FindCodec(const QString& codec_name) {
-	AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
+	// we have to break const correctness for compatibility with older ffmpeg versions
+	AVCodec *codec = (AVCodec*) avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
 	if(codec == NULL) {
 		Logger::LogError("[Muxer::FindCodec] " + Logger::tr("Error: Can't find codec!"));
 		throw LibavException();
diff --git a/src/AV/Output/VideoEncoder.cpp b/src/AV/Output/VideoEncoder.cpp
index 8087e8ed..d09d7047 100644
--- a/src/AV/Output/VideoEncoder.cpp
+++ b/src/AV/Output/VideoEncoder.cpp
@@ -95,7 +95,8 @@ unsigned int VideoEncoder::GetFrameRate() {
 }
 
 bool VideoEncoder::AVCodecIsSupported(const QString& codec_name) {
-	AVCodec *codec = avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
+	// we have to break const correctness for compatibility with older ffmpeg versions
+	AVCodec *codec = (AVCodec*) avcodec_find_encoder_by_name(codec_name.toUtf8().constData());
 	if(codec == NULL)
 		return false;
 	if(!av_codec_is_encoder(codec))
